/**
 * Copyright 2014-2015 www.fsfkj.com
 * All rights reserved.
 * 
 * @project
 * @author Flouny.Caesar
 * @version 1.0
 * @date 2015-09-11
 */
package com.eyaomall.wxmanage.common.advice;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.eyaomall.wxmanage.common.helper.MemberHelper;
import com.eyaomall.wxmanage.dao.ShopDao;
import com.eyaomall.wxmanage.model.po.OperLog;
import com.eyaomall.wxmanage.model.po.Shop;
import com.eyaomall.wxmanage.model.vo.ShopExtVO;
import com.eyaomall.wxmanage.service.OperLogService;

/**
 * 开通代理操作aop
 * @author yuhuafeng
 * @date 2016-9-7
 */
@Component
@Aspect
public class MerchantsOperLogAdvice {
	
	@Autowired
	private OperLogService operLogService;
	
	@Autowired
	private ShopDao shopDao;
	
	@Pointcut("execution(public * com.eyaomall.wxmanage.service.ShopExtService.openChild(..))")
	public void pointCut() {
		// ...
	}
	
	@Before(value="pointCut()")
	public void before(JoinPoint joinPoint) {
	}
	
	@AfterReturning(value="pointCut()" ,returning="flag")
	public void afterReturning(JoinPoint joinPoint,boolean flag) {
		if(flag){
			Object[] s=joinPoint.getArgs();
			ShopExtVO vo=null;
			for (Object obj : s) {
				if (obj instanceof ShopExtVO) {
					vo = (ShopExtVO) obj;
					break;
				}
			}
			Shop shop=(Shop) shopDao.query("queryById", vo.getShopId());
			if(shop==null)
				return;
			StringBuffer sb=new StringBuffer();
			sb.append("为");
			sb.append(shop.getCompanyName());
			sb.append("开通代理");
			OperLog log = new OperLog();
			log.setOwnerId(MemberHelper.getId());
			log.setContent(sb.toString());
			log.setType("2");
			operLogService.create(log);
		}
		
	}
}